package generic;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @program JavaBase
 * @description:
 * @author: zhanglu
 * @create: 2020-02-22 19:26:00
 */
public class Test01 {

    public static void main(String[] args) throws Exception {
        Car<Integer, String, Boolean> car = new Car<>();
        car.setT(1);
        car.setE("2");
        System.out.println(car);
        car.convert(car);
    }

}

class Car<T,E,C> {

    private T t;
    private E e;
    private C c;

    public <T> void convert(T t) throws Exception {
        Class<?> aClass = t.getClass();
        String name = aClass.getName();
        Method[] methods = aClass.getMethods();
        Field[] fields = aClass.getDeclaredFields();
        Field field = aClass.getDeclaredField("c");
//        field.setAccessible(true);
        field.set(t, true);
        Method m = aClass.getMethod("getC");
        Object invoke = m.invoke(t, null);
        System.out.println(invoke);

        Object o = aClass.newInstance();
        System.out.println(o == t);


    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public E getE() {
        return e;
    }

    public void setE(E e) {
        this.e = e;
    }

    public C getC() {
        return c;
    }

    public void setC(C c) {
        this.c = c;
    }
}
